<!--
 @description 原商家门店更新
 @fileName TakeOriginalStore.vue
 @author zengqiongying
 @created 2023/12/27 13:54:59
-->
<template>
  <div>
    <Card
      v-for="(item, i) in list"
      :key="`${i}-${item.code}`"
      :title="`门店${i + 1}`"
      no-mg
      :round="false"
      style="margin-top: 2px"
    >
      <Cell title="原门店编码" :modelValue="item.originalCode" readonly defaultValue="--" />
      <Cell title="原门店地址" :modelValue="item.originalShopAddr" :custom="true" readonly defaultValue="--" />
      <Cell
        title="新商是否接管"
        :modelValue="[1, '1'].includes(item.isNewBusinessTakeover) ? '是' : '否'"
        readonly
        defaultValue="--"
      />

      <template v-if="[1, '1'].includes(item.isNewBusinessTakeover)">
        <Cell title="门店名称" :modelValue="item.name" readonly defaultValue="--" />
        <Cell title="门店咨询电话" :modelValue="item.shopInfoPhone" readonly defaultValue="--" />
        <Cell title="门店售后电话" :modelValue="item.shopServPhone" readonly defaultValue="--" />
        <Cell title="营业执照图片" is-column custom readonly>
          <AttachmentUpload
            v-model="item.licenseList"
            view-type="image"
            type-code="ACCESS055"
            :limit="1"
            :objectId="item.id"
            :imageHeight="124"
            :imageColumn="2"
            readonly
          />
          <div v-if="item.licenseList.length === 0" class="no-data-msg">暂无数据</div>
        </Cell>
        <Cell title="专卖店特许经营合同图片" is-column custom readonly>
          <AttachmentUpload v-model="item.agreementList" type-code="ACCESS056" :objectId="item.id" readonly />
          <div v-if="item.agreementList.length === 0" class="no-data-msg">暂无数据</div>
        </Cell>
      </template>
    </Card>
    <Card v-if="list.length === 0" no-mg :round="false" style="margin-top: 1px">
      <qmp-empty description="暂无门店信息" image-size="60px" />
    </Card>
  </div>
</template>

<script lang="ts">
  import { reactive, toRefs, defineComponent } from 'vue'
  import Card from '@/components/Card/index.vue'
  import Cell from '@/components/Cell/index.vue'
  import AttachmentUpload from '@/components/AttachmentUpload/index.vue'
  import { queryShopByChangeCode } from '@/apis/ctmCustomerChange/index'
  interface anyObjectModle {
    [key: string]: any
  }

  export default defineComponent({
    name: 'DealerNewArchiveTakeOriginalStoreView',
    components: { Card, Cell, AttachmentUpload },
    props: {
      changeCode: {
        type: String,
        default: ''
      }
    },
    setup(props, { emit }) {
      const datas = reactive<anyObjectModle>({
        list: [
          /* {
            id: '1111',
            originalCode: '32132',
            originalShopAddr: '四川省成都市青羊区成飞大道189号1',
            isNewBusinessTakeover: 0,
            name: '',
            shopInfoPhone: '',
            shopServPhone: '',
            licenseList: [],
            agreementList: []
          },
          {
            id: '2222',
            originalCode: '321322',
            originalShopAddr: '四川省成都市青羊区成飞大道189号2',
            isNewBusinessTakeover: 0,
            name: '',
            shopInfoPhone: '',
            shopServPhone: '',
            licenseList: [],
            agreementList: []
          },
          {
            id: '3333',
            originalCode: '3213222',
            originalShopAddr: '四川省成都市青羊区成飞大道189号3',
            isNewBusinessTakeover: 0,
            name: '',
            shopInfoPhone: '',
            shopServPhone: '',
            licenseList: [],
            agreementList: []
          } */
        ]
      })

      const getDetail = () => {
        const changeCode = props.changeCode || ''
        if (!changeCode) return
        queryShopByChangeCode(changeCode).then((res: any) => {
          const list = res.data || []
          datas.list = list.map((v: any) => {
            return { ...v, ...{ licenseList: [], agreementList: [] } }
          })
        })
      }

      getDetail()

      return {
        ...toRefs(datas)
      }
    }
  })
</script>
<style lang="less" scoped>
  @import url('../../styles/common.less');
</style>
